package cn.seocoo.platform.web.controller.base;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.base.domain.BaseBrand;
import cn.seocoo.platform.base.service.IBaseBrandService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * 品牌 信息操作处理
 * 
 * @author wujian
 * @date 2019-12-25
 */
@Controller
@RequestMapping("/base/baseBrand")
public class BaseBrandController extends BaseController
{
    private String prefix = "base/baseBrand";
	
	@Autowired
	private IBaseBrandService baseBrandService;
	
	@RequiresPermissions("base:baseBrand:view")
	@GetMapping()
	public String baseBrand()
	{
	    return prefix + "/baseBrand";
	}
	
	/**
	 * 查询品牌列表
	 */
	@RequiresPermissions("base:baseBrand:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BaseBrand baseBrand)
	{
		startPage();
        List<BaseBrand> list = baseBrandService.selectBaseBrandList(baseBrand);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出品牌列表
	 */
	@RequiresPermissions("base:baseBrand:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseBrand baseBrand)
    {
    	List<BaseBrand> list = baseBrandService.selectBaseBrandList(baseBrand);
        ExcelUtil<BaseBrand> util = new ExcelUtil<BaseBrand>(BaseBrand.class);
        return util.exportExcel(list, "baseBrand");
    }
	
	/**
	 * 新增品牌
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存品牌
	 */
	@RequiresPermissions("base:baseBrand:add")
	@Log(title = "品牌", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BaseBrand baseBrand)
	{		
		return toAjax(baseBrandService.insertBaseBrand(baseBrand));
	}

	/**
	 * 修改品牌
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		BaseBrand baseBrand = baseBrandService.selectBaseBrandById(id);
		mmap.put("baseBrand", baseBrand);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存品牌
	 */
	@RequiresPermissions("base:baseBrand:edit")
	@Log(title = "品牌", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BaseBrand baseBrand)
	{		
		return toAjax(baseBrandService.updateBaseBrand(baseBrand));
	}
	
	/**
	 * 删除品牌
	 */
	@RequiresPermissions("base:baseBrand:remove")
	@Log(title = "品牌", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(baseBrandService.deleteBaseBrandByIds(ids));
	}
	
}
